<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Gass auth users Class
 *
 * 该类作为学生操作访问的控制类
 * @author Jason Chan
 */ 
class Gass_users extends CI_Controller { 
  function __construct() 
  {
    parent::__construct();

		$this->load->database();
		$this->load->library('session');
 		$this->load->helper('url');
 		$this->load->helper('form');

  	$this->auth = new stdClass;
    $this->load->library('flexi_auth');	

    //检查用户是否登录
    if (!$this->flexi_auth->is_logged_in_via_password()) 
    {
			$this->flexi_auth->set_error_message('您尚未登陆系统！', TRUE);
			$this->session->set_flashdata('message', $this->flexi_auth->get_messages());
			redirect('gass_auth');
		}
    
    $this->config->load('gass_conf');
		$this->load->vars('base_url', $this->config->item('base_url'));
		$this->load->vars('includes_dir', $this->config->item('includes_dir'));
		$this->load->vars('current_url', $this->uri->uri_to_assoc(1));
		
		$this->data = null;
		//$this->output->enable_profiler(TRUE);
	}
	
 	/**
 	 * 更新个人用户账户的数据聚合页面
 	 *
 	 * 更新用户基本的登陆信息，包括用户名、密码、邮箱等
 	 */
	function update_user_account($user_id)
	{
		if ($this->input->post('update_form_submit')) 
		{
			$this->load->model('gass_users_model');
			$this->gass_users_model->update_person_account($user_id);
        }else if($this->input->post('change_password'))
        {
			$this->load->model('gass_users_model');
			$this->gass_users_model->change_password();
        }
		
		$sql_where = array($this->flexi_auth->db_column('user_acc', 'id') => $user_id);
		$this->data['user'] = $this->flexi_auth->get_users_row_array(FALSE, $sql_where);

		$this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];		
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
		$this->load->view('gass_users/u_account_update_view', $this->data);
	}	

 	/**
 	 * 更改密码
 	 * 
 	 */
	function change_password()
	{
		if ($this->input->post('change_password'))
		{
			$this->load->model('gass_users_model');
			$this->gass_users_model->change_password();
		}
		$this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];
		$this->load->view('gass_users/password_update_view', $this->data);
	}
	
}
